<?php
declare (strict_types = 1);
namespace app\admin\controller;

use think\facade\Session;
use think\Request;
use think\facade\View;
use think\exception\ValidateException;

use app\admin\validate\SystemValidate;

use app\admin\model\System;

class SystemController extends BaseController
{
    // 渲染参数列表页面
    public function system_list()
    {   
        $systemModel = new System();

        $info = $systemModel->getFind(['id' => 1])['data'];

        View::assign('info', $info);
        return view();
    }

    // 参数信息修改
    public function setEdit()
    {   
        $systemModel = new System();
        $data = input('post.');

        // 验证数据
        try{
            validate(SystemValidate::class)->scene('edit')->check($data);
        }catch(ValidateException $e){
            $this->error_back($e->getError());
        }
        
        $data['id'] = 1;
        $flag = $systemModel->edit($data);

        if($flag['code'] != 'ok'){
            $this->error_back($flag['msg']);
        }

        $this->success_back('修改成功');
    }
}
